<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <script src="https://unpkg.com/vue"></script>
    <title>Title</title>
    <script>
        window.onload=function(){
            var app4 = new Vue({
                el: '#app-4',
                methods:{
                  reverseMessage:function(){
                      this.message = this.message.split('').reverse().join('')
                  },
                    time:function(){
                      var x={name:this.username,age:this.userage,time:new Date()}
                              this.ps.push(x);
                    },
                    addpeople:function(){
                    this.peoples.push({name:this.username,age:this.age,time:new Date()});},
                    removeall:function(){
                        this.peoples=[];
                    },
                    remove:function(index){
                        this.peoples.splice(index,1);
                    }
                },
                data: {
                    username:'',
                    age:null,
                    message: '用户信息表',
                    peoples:[
                        { name: 'cjy',age:'20',time:new Date() },
                        { name:'jxc',age:'33',time:new Date() },

                    ]
                },
                filters:{
                    hhmmss:function(val){
                        return(val.getHours()+":"+val.getMinutes()+":"+val.getSeconds());
                    },
                    capitalize: function (value) {
                        if (!value) return ''
                        value = value.toString()
                        return value.charAt(0).toUpperCase() + value.slice(1)
                    }
                }
            })
        }
    </script>
</head>
<body>
<div id="app-4">
    <p>{{message}}</p>
    <input v-model="username">
    <input v-model="age">
    <button v-on:click="addpeople">添加</button>
    <button v-on:click="removeall">删除所有</button>
    <button v-on:click="reset">重置</button>
    <table border="1">
        <tr><th>序号</th><th>名字</th><th>年龄</th><th>时间</th><th>操作</th></tr>
        <tr v-for="(todo,index) in peoples">
            <td>{{index+1}}</td>
            <td>{{todo.name | capitalize}}</td>
            <td>{{todo.age}}</td>
            <td>{{todo.time.getHours()+":"+todo.time.getMinutes()+":"+todo.time.getSeconds()}}</td>
            <td><button v-on:click="remove(index)">删除</button></td>
        </tr>
    </table>
</div>
</div>
</body>
</html>